﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BusinessPlatform.Core.BusinessObject.Properties;

namespace BusinessPlatform.Core.BusinessObject.BOParser
{
    internal class BOChildren : IBOChildren
    {
        private IBusinessObjectListBase _BusList;

        public BOChildren(IBusinessObjectListBase entityList)
        {
            _BusList = entityList;
        }
        public IBusinessObjectBase Parent { get; set; }

        public Type ChildType
        {
            get { return _BusList.GetChildType(); }
        }

        public IBusinessObjectListBase BOList
        {
            get { return _BusList; }
            set { _BusList = value; }
        }

        public IList<BusinessObjectBase> Children
        {
            get
            {
                IList<BusinessObjectBase> _Children = new List<BusinessObjectBase>();
                foreach (var item in BOList)
                {
                    _Children.Add(item as BusinessObjectBase);
                }
                return _Children;
            }
        }

        public Criteria.ICriteria Criteria
        {
            get
            {
                //子对象的查询条件
                var cri = new Criteria.Criteria();
                var con = cri.Conditions.New();
                var iPropertiesManager = (Parent as BusinessObjectBase).PropertiesManager;
                con.FieldName = iPropertiesManager.GetPrimaryPropertyInfo().Name;
                con.Operation = Core.Criteria.EnumOperateSymbol.EQUAL;
                con.ConditionValue = iPropertiesManager.GetPrimaryPropertyInfo().PropertyValue.ToString();
                return cri;
            }
        }

    }
}
